<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');
$this->load->helper('url');
?>	<table id="tt" class="easyui-datagrid"></table>
	
	
	<div id="tb" style="padding:10px;5px;height:auto">
		<div>
			编号: <input id="id" class="easyui-textbox" style="width:80px">
			用户名: <input id="username" class="easyui-textbox" style="width:100px">
			日期 从: <input class="easyui-datebox" id="start" style="width:100px">
			到: <input class="easyui-datebox" id="end" style="width:100px">
			状态：
			<select id="status" class="easyui-combobox">
				<option value="-1">全部</option>
				
<?php
foreach ($status as $k => $v) {
?>				<option value="<?php echo $k;?>"><?php echo $v;?></option>
				<?php
}

?>			</select>
			币种：
			<select id="coin_id" class="easyui-combobox" style="width:100px">
				<option value="0">全部</option>
				
<?php
foreach ($coins as $v) {
?>				<option value="<?php echo $v['id'];?>"><?php echo $v['cn_name'];?></option>
				<?php
}

?>			</select>
			<a href="#" onclick="doSearch()" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
		</div>
		<div style="margin-top:10px">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="add">添加</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" id="del">删除</a>
		</div>
	</div>
	<div id="win"></div>

<script language="javascript">

$(function(){
	$('#tt').datagrid({
		url:'<?php echo site_url('items/data');?>',
		pagination:true,
		pageSize:20,
		toolbar:'#tb',
		checkbox:true,
		fit:true,
		border:false,
		idField:'id',
		'columns':[[
			{field:'ck',checkbox:'true'},
			{field:'id',width:'9%',title:'编号'},
			{field:'name',width:'15%',title:'项目名称'},
			{field:'target_amount',width:'15%',title:'目标金额'},
			{field:'day',width:'10%',title:'项目周期'},
			{field:'username',width:'15%',title:'发布者帐号'},
			{field:'add_time',width:'10%',title:'发布时间'},
			{field:'status',width:'10%',title:'状态',formatter:function(value,row,index){
				if(row.status == 0){
					return '未发布';
				}else if(row.status == 1){
					return '待审核';
				}else if(row.status == 2){
					if(row.stat == 0){
						return '即将开始';
					}else if(row.stat == 1){
						return '进行中';
					}else if(row.stat == 2){
						return '已成功';
					}else if(row.stat == 3){
						return '已失败';
					}
				}else if(row.status == 7){
					return '已发放代币';
				}else{
					return '已成功';
				}
			}},
			{field:'action',width:'15%',title:'操作',formatter:function(value,row,index){
				$s = '<a href="javascript:doedit('+row.id+')" iconCls="icon-edit" class="list_link easyui-linkbutton">修改</a>';
				if(row.status == 1) $s += ' <a iconCls="icon-ok" data-id="'+row.id+'" data-status="2" class="pass-btn list_link easyui-linkbutton">通过</a> <a iconCls="icon-ok" data-id="'+row.id+'" data-status="-1" class="nopass-btn list_link easyui-linkbutton">未通过</a>';
				if((row.stat == 2 || row.stat == 3) && row.status == 2) {
					$s += ' <a iconCls="icon-ok" data-id="'+row.id+'" data-status="7" class="repay-btn list_link easyui-linkbutton">发放代币</a>';
				}else{
					$s += ' <a iconCls="icon-ok" style="background:#ddd;" class="list_link easyui-linkbutton">发放代币</a>';
				}
				return  $s;
			}},
		]],
		onLoadSuccess:function(data){$(".list_link").linkbutton()}
	});

	$.set_status('.nopass-btn','<?php echo site_url('items/set_status');?>');
	$.set_status('.pass-btn','<?php echo site_url('items/set_status');?>');
	$.set_status('.repay-btn','<?php echo site_url('items/repay');?>');

	$('#win').window({
		width:"100%",
		height:"100%",
		modal:true,
		closed:true,
		title:'添加/修改'
	});

	$('#add').click(function(){
		$('#win').window('open');
		$('#win').window('refresh', '<?php echo site_url('items/add');?>');
	});

	$('#del').click(function(){
		var rows = $('#tt').datagrid('getChecked');
		if(rows.length == 0){  
			$.messager.alert('Info','请至少选择一行数据！','info');
			return false;  
		}

		var ids = [];
		$.each(rows,function(index,item){
			ids.push(item.id);
		});
		
		$.messager.confirm('确认信息','您确定要删除吗？删除之后不能恢复',function(r){
			if(r){
				$.getJSON('<?php echo site_url('items/del');?>',{'id[]':ids},function(d){
					$.messager.alert('信息提示',d.msg,'info');
					
					if(d.error == 0){
						$('#tt').datagrid('reload');
					}
				});
			}
		});
		
	});
});
function doSearch(){
	$('#tt').datagrid('load',{
		id: $('#id').val(),
		username: $('#username').val(),
		start: $('#start').val(),
		end: $('#end').val(),
		status: $('#status').val(),
		coin_id: $('#coin_id').val()
	});
}
function doedit(id){
	$('#win').window('open');
	$('#win').window('refresh', '<?php echo site_url('items/edit/\'+id+\'');?>');
}
</script>